package com.cskaoyan.app.wxservice.impl;

import com.cskaoyan.app.bean.po.MarketFeedback;
import com.cskaoyan.app.bean.po.MarketUser;
import com.cskaoyan.app.mapper.MarketFeedbackMapper;
import com.cskaoyan.app.mapper.MarketUserMapper;
import com.cskaoyan.app.wxservice.WxFeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {

    @Autowired
    MarketFeedbackMapper feedbackMapper;

    @Autowired
    MarketUserMapper userMapper;

    @Override
    public void addFeedback(MarketFeedback feedback) {
        Subject subject = SecurityUtils.getSubject();
        Integer userid = (Integer) subject.getSession().getAttribute("userid");
        MarketUser user = userMapper.selectByPrimaryKey(userid);
        feedback.setUserId(userid);
        feedback.setUsername(user.getUsername());
        feedback.setAddTime(new Date());
        feedback.setUpdateTime(new Date());
        feedbackMapper.insertSelective(feedback);
    }
}
